package com.bringway.p2p.service.impl;

import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bringway.global.util.StringUtils;
import com.bringway.p2p.dao.P2pWdzrDao;
import com.bringway.p2p.service.P2pWdzrService;

import net.sf.json.JSONObject;
@Service
@Transactional
public class P2pWdzrServiceImpl implements P2pWdzrService{
	
	private static Logger logger=Logger.getLogger(P2pWdzrServiceImpl.class);
	@Autowired
	private P2pWdzrDao p2pWdzrDao;

	@Override
	public List<Map<String, Object>> queryWdzrSqList(JSONObject params) {
		return p2pWdzrDao.queryWdzrSqList(params);
	}

	@Override
	public int getWdzrSqCount(JSONObject params) {
		return p2pWdzrDao.getWdzrSqCount(params);
	}

	@Override
	@Transactional("p2p")
	public boolean saveWdzrSh(JSONObject params) {
		//更新我的转让 成功并审核通过-更新原投资状态 转让中
		//更新我的转让 失败或审核不通过-更新原投资状态 成功
		boolean isScuUpWdzr=p2pWdzrDao.saveWdzrSh(params)>0?true:false;
		String shzt=params.optString("shzt");
		String zrly=params.optString("zrly");
		if (isScuUpWdzr&&StringUtils.equals("01", shzt)) {
			params.put("zrzt", "01");
			params.put("tzzt", "转让中");
		} else {
			params.put("zrzt", "02");
			params.put("tzzt", "成功");
		}
			p2pWdzrDao.updateWdzrTzrxx(params);
		if (StringUtils.equals("01", zrly)) {
			p2pWdzrDao.updateTzrxx(params);
		} else {
			p2pWdzrDao.updateJhnTzrxx(params);
		}
		return isScuUpWdzr;
	}

	@Override
	public List<Map<String, Object>> queryZrTzrxxList(JSONObject params) {
		return p2pWdzrDao.queryZrTzrxxList(params);
	}

	@Override
	public int getZrTzrxxCount(JSONObject params) {
		return p2pWdzrDao.getZrTzrxxCount(params);
	}

	@Override
	public float getZrTzrxxSum(JSONObject params) {
		return p2pWdzrDao.getZrTzrxxSum(params);
	}

	@Override
	public boolean isValid(JSONObject params) {
		return p2pWdzrDao.isValid(params)>0?true:false;
	}

	@Override
	public List<Map<String, Object>> queryWdzrView(JSONObject params) {
		return p2pWdzrDao.queryWdzrView(params);
	}

	@Override
	public int queryWdzrCount(JSONObject params) {
		return p2pWdzrDao.queryWdzrCount(params);
	}

	@Override
	public List<Map<String, Object>> queryWdzrQxList(JSONObject params) {
		return p2pWdzrDao.queryWdzrQxList(params);
	}

	@Override
	public int getWdzrQxCount(JSONObject params) {
		return p2pWdzrDao.getWdzrQxCount(params);
	}

	@Override
	public JSONObject saveWdzrQx(JSONObject params) {
		return p2pWdzrDao.saveWdzrQx(params);
	}

	@Override
	public boolean deleteWdzrQx(String username) {
		return p2pWdzrDao.deleteWdzrQx(username);
	}

}
